package com.lynn.common.utils;

import android.os.Handler;
import android.os.Looper;

public class ThreadUtil {


    /**
     * 主线程运行
     *
     * @param r
     */
    public static void runOnMainThread(Runnable r) {
        if (mainThread())
            r.run();
        else
            new Handler(Looper.getMainLooper()).post(r);
    }


    /**
     * 判断当前线程是否是主线程
     */
    public static boolean mainThread() {
        return Thread.currentThread() == Looper.getMainLooper().getThread();
    }

}
